const Router = require('koa-router');
const tool = require("../../tools/tool");
const router = new Router();
const {db, Op, QueryTypes} = require("../../models/db");
// 商品历史价格
router.post('/bill/altBiz', async ctx => {
    try {
        let user = ctx.user
        let body = ctx.request.body
        let tenantId = user.tenantId;
        let billId = body.billId;
        let salesId = tool.xe.toNumber(body.salesId);
        if(!salesId) return ctx.err('请选择业务员')
        // let salesName = body.salesName
        let model = await db.models['invoice'].findOne({
            where: {
                tenantId,
                id: billId
            }
        })
        if(model) {
            model.salesId = salesId
            await model.save()
            await tool.saveLogInvoice(tenantId, user.id, billId, '修改业务员', model)
        }
        return ctx.suc('已修改')
    }
    catch (e) {
        return ctx.err(e)
    }
})

module.exports = router;